
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppDoc;
import me.zhengjie.service.AppDocService;
import me.zhengjie.service.dto.AppDocQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "文档管理管理")
@RequestMapping("/api/appDoc")
public class AppDocController {

    private final AppDocService appDocService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appDoc:list')")
    public void exportAppDoc(HttpServletResponse response, AppDocQueryCriteria criteria) throws IOException {
        appDocService.download(appDocService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询文档管理")
    @ApiOperation("查询文档管理")
    @PreAuthorize("@el.check('appDoc:list')")
    public ResponseEntity<Object> queryAppDoc(AppDocQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appDocService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增文档管理")
    @ApiOperation("新增文档管理")
    @PreAuthorize("@el.check('appDoc:add')")
    public ResponseEntity<Object> createAppDoc(@Validated @RequestBody AppDoc resources){
        return new ResponseEntity<>(appDocService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改文档管理")
    @ApiOperation("修改文档管理")
    @PreAuthorize("@el.check('appDoc:edit')")
    public ResponseEntity<Object> updateAppDoc(@Validated @RequestBody AppDoc resources){
        appDocService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除文档管理")
    @ApiOperation("删除文档管理")
    @PreAuthorize("@el.check('appDoc:del')")
    public ResponseEntity<Object> deleteAppDoc(@RequestBody Integer[] ids) {
        appDocService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}